<?php

namespace app\admin\model;

class Group extends \think\Model
{
    protected $name = 'group';

    public static function onBeforeDelete($model){
        //检查是否存在用户
        if(Admin::where(['group_id'=>$model['id']])->find()){
            throw new \Exception('请先删除当前角色的用户');
        }
    }
    
    // public static function onBeforeDelete($model)
    // {
    //     dump($model);exit;
    //     //查询所有子角色是否存在用户
    //     if (User::where(['group_id' => $model['id'], 'type' => 1])->find()) {
    //         throw new \Exception('子角色还存在用户,请先删除或更改角色组');
    //         return false;
    //     }
    // }
}
